package RockPaperScissors
{
    public class ProcessorStep implements IProcessable
    {
        import RockPaperScissors.Utilities;
        
        var _onComplete:Function;
        var _onFail:Function;
        
        public function ProcessorStep(onComplete:Function = null, onFail:Function = null)
        {
            this.setupProcessorStep(onComplete, onFail);
        }
        
        
        public virtual function Process(data:*)
        {
            //this.createCallBack(function(event, data){return data;}, data);
        }
        
        
        protected function startProcessing(event:*, fn:Function, data)
        {
            data = fn(event, data);
            this.ProcessingComplete(data);
        }
        
        protected function ProcessingError(data)
        {
            this._onFail(data);
        }
        protected function ProcessingComplete(data)
        {
            this._onComplete(data);
        }
        
        protected function processWithThis(fn:Function, args:*, context:*):Function
        {
            
            return function(event:*)
            {
                context.startProcessing(event, fn, args);
            }
        }
        
        protected function setupProcessorStep(onComplete:Function, onFail:Function)
        {
            this._onComplete = onComplete;
            this._onFail = onFail;
        }
    }
}